<template>
  <div class="container">
    <div @click="fly('/')">首页</div>
    <div class="category-header">
      <span v-if="cat == '山地车'">山地车</span>
      <span v-else-if="cat == '公路车'">公路车</span>
      <span v-else-if="cat == '电动车'">电动车</span>
      <div class="good">分类</div>
    </div>
    <div class="goods-row">
      <el-row :gutter="20">
        <el-col :span="5" v-for="item in catId" :key="item.id" class="goods-col">
          <div class="product-card">
            <img @click="fly('/detail/?id=' + item.id)" :src="require('@/assets/' + item.img)" alt="Product Image" class="product-image">
            <div class="product-details">
              <h3>{{ item.description1 }}</h3>
              <p>￥{{ item.dayPrice }}元/天</p>
              <p>￥{{ item.monthPrice }}元/月</p>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    let result = this.$route.query.categoryId;
    return {
      cat: result,
      catId: []
    };
  },
  mounted() {
    this.load();
  },
  methods: {
    async load() {
      let result = await this.$axios.get('/bikecat/' + this.cat);
      this.catId = result.data.data;
    },
    async fly(url) {
      location.href = url;
    }
  }
}
</script>
<style scoped>
  .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

  .category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 10px 20px;
  background-color: #f8f8f8;
  border-radius: 8px;
  color: #FF6347;
  font-size: 24px;
  font-weight: bold;
}

  .goods-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
    margin-top: 10px;
}

  .goods-col {
  flex: 0 0 33.333%;
  max-width: 33.333%;
}

  .product-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
    margin-top: 20px;
}

  .product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

  .product-image {
  width: 100%;
  height: 250px;
  object-fit: cover;
  background-color: #f0f0f0; /* Fallback color for empty images */
}

  .product-details {
  padding: 15px;
  text-align: center;
}

  h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

  p {
  margin: 5px 0;
  font-size: 14px;
  color: #666;
}

  .good {
  background-color: forestgreen;
  width: 100px;
  text-align: center;
  margin-left: 10px;
  height: 40px;
  font-size: 16px;
  border-radius: 10px;
  line-height: 40px;
  color: white;
  font-weight: bold;
}

  /* 响应式设计 */
  @media (max-width: 992px) {
  .goods-col {
  flex: 0 0 50%;
  max-width: 50%;
}
  .product-image {
  height: 200px;
}
}

  @media (max-width: 576px) {
  .goods-col {
  flex: 0 0 100%;
  max-width: 100%;
}
  .product-image {
  height: 150px;
}
  .category-header {
  flex-direction: column;
  align-items: flex-start;
}
  .good {
  width: auto;
}
}
</style>